﻿using Ninject;
using Romantics.Domain;
using Romantics.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Romantics.Controllers
{
    public class PhotoController : Controller
    {
        private readonly IDomainRepository _domainRepository;

        public PhotoController(IDomainRepository domainRepository)
        {
            _domainRepository = domainRepository;
        }

        public ViewResult Index(int id)
        {
            var listViewModel = HikeViewModel.GetPhotoAlbumItem(_domainRepository, id);
            if (listViewModel.PhotoAlbumItem.PhotoAlbum == null || !listViewModel.PhotoAlbumItem.PhotoAlbum.Published)
                throw new HttpException(404, "Post not found");
            return View("Photo", listViewModel);
        }

        /// <summary>
        /// Child action that returns the sidebar partial view.
        /// </summary>
        /// <returns></returns>
        [ChildActionOnly]
        public PartialViewResult Sidebars(string action)
        {
            if (action.Equals("Photo", StringComparison.InvariantCultureIgnoreCase))
                action = "index";

            var widgetViewModel = new WidgetViewModel(_domainRepository, action);
            if (RouteData.Values.ContainsKey("category_url"))
            {
                ViewBag.Category = _domainRepository.Category(RouteData.Values["category_url"].ToString());
            }
            if (RouteData.Values.ContainsKey("region_url"))
            {
                ViewBag.Region = _domainRepository.Region(RouteData.Values["region_url"].ToString());
            }
            if (RouteData.Values.ContainsKey("year"))
            {
                ViewBag.Year = RouteData.Values["year"].ToString();
            }
            return PartialView("_Sidebars", widgetViewModel);
        }
    }
}
